package io.github.talelin.latticy.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import io.github.talelin.core.annotation.PermissionMeta;
import io.github.talelin.core.annotation.PermissionModule;
import io.github.talelin.latticy.dto.order.PageListDTO;
import io.github.talelin.latticy.dto.order.TakeDownPageListDTO;
import io.github.talelin.latticy.service.PutAwayService;
import io.github.talelin.latticy.service.feign.OrderFeignService;
import io.github.talelin.latticy.vo.FindResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName：OrderController
 * @Author: ljj
 * @Date: 2022/8/10 10:07
 */
@RestController
@RequestMapping("/v1/order")
@PermissionModule(value = "订单管理")
public class OrderController {

    @Autowired
    private OrderFeignService orderFeignService;

    @Autowired
    private PutAwayService putawayService;

    @PermissionMeta(value = "查询列表")
    @PostMapping("/takeDownPageList")
    public FindResultVO takeDownPageList(@RequestBody @Validated TakeDownPageListDTO pageListDTO) {
        if(CollectionUtils.isNotEmpty(pageListDTO.getAreaIds())){
            List<String> skus = putawayService.getSkuByLocationId(pageListDTO.getAreaIds());
            if(CollectionUtils.isEmpty(skus)){
                return FindResultVO.success();
            }
            pageListDTO.setSkus(skus);
        }
        return orderFeignService.takeDownPageList(pageListDTO);
    }


    @GetMapping("/findById/{id}")
    public FindResultVO findById(@PathVariable Long id){
        return orderFeignService.findById(id);
    }

    @GetMapping("/pageList")
    public FindResultVO pageList(PageListDTO pageListDTO){
        return orderFeignService.pageList(pageListDTO);
    }
}
